package cn.cas.mango.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@Slf4j
@Data
public class HotSpotNews {
  // 发生时间
  @JsonProperty(value = "fssj")
  private String newsPublicDate;
  // 关键词
  @JsonProperty(value = "keywords")
  private Object newsKeywords;
  // 来源省市
  @JsonProperty(value = "lyss")
  private Object fromProvince;
  // key
  @JsonProperty(value = "nm")
  private String id;
  @JsonProperty(value = "zlnm")
  private String MaterialId;
  // 标题
  @JsonProperty(value="sjmc")
  private String newsTitleZh;
  // 内容
  @JsonProperty(value="sjms")
  private String newsContentZh;
  // 所属领域
  @JsonProperty(value = "ssly")
  private Object area;
  @JsonProperty(value = "entities")
  private Object newsEntities;
  @JsonProperty(value = "entities_organization")
  private Object newsEntitiesOrganization;
  @JsonProperty(value = "entities_place")
  private Object newsEntitiesPlace;
  @JsonProperty(value = "entities_person")
  private Object newsEntitiesPerson;

  @JsonProperty(value = "drsj")
  private String drsj;

  private Object vector;
  private Object contentVector;
  private Object titleContentVector;
  @JsonProperty(value = "area")
  private Object place;

  public List<String> getFilteredKeywords(Set<String> blackList) {
    Object o = newsKeywords;
    if (o instanceof Map) {
      Object finalO = o;
      o = new ArrayList<Map>(){{add((Map) finalO);}};
    } else if (o == null) {
      o = new ArrayList<>();
    }

    if (!((List)o).isEmpty()) {
      List<Map> temp = new ArrayList<>();
      List list = (List) o;
      for (Object s: list) {
        if (s instanceof Map) {
          temp.add((Map)s);
        } else {
          Map<String, Object> map = new LinkedHashMap<>();
          map.put("name", s);
          map.put("score", 0.1);
          temp.add(map);
        }
      }
      o = temp;
    }
    try {
      o = ((List<Map>) o).stream().filter(x->!blackList.contains(x.get("name"))).collect(Collectors.toList());
    } catch (Exception e) {
    }
    return ((List<Map>) o).stream().map(x->(String)x.get("name")).collect(Collectors.toList());
  }

}
